package settings

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"log"
	"os"
)

type Config struct {
	Server App
	Db Db
}

type App struct {
	Name string
	Port int
}

type Db struct {
	Username string
	Password string
	Host     string
	Port     int
	Database string
}

var GlobalConfig = Config{}

func SetupApp() {
	var file = "./setting.yaml"
	stat, err := os.Stat(file)
	if err != nil {
		fmt.Println(err)
		return
	}
	var fileData = make([]byte, stat.Size())
	open, err2 := os.Open(file)
	if err2 != nil {
		log.Println(err2)
	}
	_, _ = open.Read(fileData)
	//content := string(fileData)

	err3 := yaml.Unmarshal(fileData, &GlobalConfig)
	if err3 != nil {
		fmt.Println(err3)
	}

}
